//
//  JMProgress.m
//  JMBaseProject
//
//  Created by liuny on 2018/7/15.
//  Copyright © 2018年 liuny. All rights reserved.
//

#import "JMProgressHelper.h"

@implementation JMProgressHelper
+(void)toastInWindowWithMessage:(NSString *)message{
    delayOperation(0, ^{
        UIWindow *window = [UIApplication sharedApplication].delegate.window;
        // 快速显示一个提示信息
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES];
        hud.mode=MBProgressHUDModeText;
        hud.label.text=message;
        hud.label.font= [UIFont systemFontOfSize:15];
        hud.label.numberOfLines = 0;
        // 隐藏时候从父控件中移除
        hud.removeFromSuperViewOnHide = YES;
        //代表需要蒙版效果
        hud.label.textColor = WhiteColor();
        hud.bezelView.blurEffectStyle = UIBlurEffectStyleDark;
        hud.contentColor = WhiteColor();
        //    hud.dimBackground = YES;
        hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
        // X秒之后再消失
        [hud hideAnimated:YES afterDelay:1.5];
    });
}

+(void)toastInWindowWithMessage:(NSString *)message afterDelay:(NSTimeInterval)delay{
    UIWindow *window = [UIApplication sharedApplication].delegate.window;
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES];
    hud.mode=MBProgressHUDModeText;
    hud.label.text=message;
    hud.label.font= [UIFont systemFontOfSize:15];
    hud.label.numberOfLines = 0;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    //代表需要蒙版效果
    
    //    hud.dimBackground = YES;
    hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
    // X秒之后再消失
    [hud hideAnimated:YES afterDelay:delay];
}

+(void)toastInWindowWithMessage:(NSString *)message dismissBlock:(void (^)(void))block{
    UIWindow *window = [UIApplication sharedApplication].delegate.window;
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES];
    hud.mode=MBProgressHUDModeText;
    hud.label.text=message;
    hud.label.font= [UIFont systemFontOfSize:15];
    hud.label.numberOfLines = 0;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    hud.label.textColor = WhiteColor();
    hud.bezelView.blurEffectStyle = UIBlurEffectStyleDark;
    hud.contentColor = WhiteColor();

    //代表需要蒙版效果
    //    hud.dimBackground = YES;
    hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
    // 消息之后执行的操作
    hud.completionBlock = block;
    // X秒之后再消失
    [hud hideAnimated:YES afterDelay:1.5];
}

+(void)toastInView:(UIView *)view message:(NSString *)message{
    
}

+(void)toastInView:(UIView *)view message:(NSString *)message dismissBlock:(void(^)(void))block{
    
}

+(void)loadingInWindowWithMessage:(NSString *)message{
    delayOperation(0, ^{
        // 快速显示一个提示信息
        UIWindow *window = [UIApplication sharedApplication].delegate.window;

        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES];
        hud.contentColor = WhiteColor();
        hud.bezelView.blurEffectStyle = UIBlurEffectStyleDark;
        hud.label.textColor = WhiteColor();
        hud.mode = MBProgressHUDModeIndeterminate;
        hud.label.text = message;
        hud.removeFromSuperViewOnHide = NO;
        [hud hideAnimated:YES afterDelay:20];
        
    });

}
+(void)toastSuccessInWindow:(NSString *)message dismissBlock:(void (^)(void))block{
    UIWindow *window = [UIApplication sharedApplication].delegate.window;
    // 快速显示一个提示信息
   __block MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES];
    hud.mode=MBProgressHUDModeText;
    hud.label.text=message;
    hud.label.font= [UIFont systemFontOfSize:15];
    hud.label.numberOfLines = 0;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    hud.label.textColor = WhiteColor();
    hud.bezelView.blurEffectStyle = UIBlurEffectStyleDark;
    
    //代表需要蒙版效果
    //    hud.dimBackground = YES;
    hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
    // 消息之后执行的操作
    hud.completionBlock = block;
    // X秒之后再消失
    UIImageView *checkmarkImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"auth_success"]]; // 替换为你的成功对勾图片
    hud.customView = checkmarkImageView;
    hud.mode = MBProgressHUDModeCustomView;
    hud.label.font= Font(14);
    hud.contentColor = WhiteColor();
    [hud hideAnimated:YES afterDelay:1.5];
}

+(void)toastSuccessInWindow:(NSString *)message second:(NSInteger)sec dismissBlock:(void (^)(void))block{
    UIWindow *window = [UIApplication sharedApplication].delegate.window;
    // 快速显示一个提示信息
   __block MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES];
    hud.mode=MBProgressHUDModeText;
    __block NSInteger second = sec;
    hud.label.text=[NSString stringWithFormat:@"%@\n\n%lds",message,second];
    delayOperation(0.01, ^{
        [JMControl changeTextColorWithLabel:hud.label changeStr:[NSString stringWithFormat:@"%lds",second] color:Hex_Str_COLOR(@"#858585")];
    });
    hud.label.font= [UIFont systemFontOfSize:15];
    hud.label.numberOfLines = 0;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    hud.label.textColor = WhiteColor();
    hud.bezelView.blurEffectStyle = UIBlurEffectStyleDark;
    
    //代表需要蒙版效果
    //    hud.dimBackground = YES;
    hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
    // 消息之后执行的操作
    hud.completionBlock = block;
    // X秒之后再消失
    UIImageView *checkmarkImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"auth_success"]]; // 替换为你的成功对勾图片
    hud.customView = checkmarkImageView;
    hud.mode = MBProgressHUDModeCustomView;
    hud.label.font= Font(14);
    hud.contentColor = WhiteColor();
    NSTimer *timer = [NSTimer timerWithTimeInterval:1 repeats:YES block:^(NSTimer * _Nonnull timer) {
        second--;
        hud.label.text = [NSString stringWithFormat:@"%@\n\n%lds",message,second];
        [JMControl changeTextColorWithLabel:hud.label changeStr:[NSString stringWithFormat:@"%lds",second] color:Hex_Str_COLOR(@"#858585")];
        if (second==0) {
            [timer invalidate];
        }
    }];
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
    [hud hideAnimated:YES afterDelay:3];
}


+(void)hidenLoadingInWindow{
    delayOperation(0.03, ^{
        UIWindow *window = [UIApplication sharedApplication].delegate.window;
        [MBProgressHUD hideHUDForView:window animated:YES];
    });
}

@end
